package com.atguigu.controller;

import com.atguigu.base.BaseController;
import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Date:2022/11/2
 * Author:ybc
 * Description:
 */
@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {

    @DubboReference
    private DictService dictService;

    @RequestMapping
    public String index(){
        return "dict/index";
    }

    @RequestMapping("/findZnodes")
    @ResponseBody
    public Result findZnodes(@RequestParam(defaultValue = "0") Long parentId){
        List<Map<String, Object>> znodes = dictService.findZnodes(parentId);
        return Result.ok(znodes);
    }

    @RequestMapping("/findDictListByParentId/{parentId}")
    @ResponseBody
    public Result findDictListByParentId(@PathVariable Long parentId){
        List<Dict> dictList = dictService.findDictListByParentId(parentId);
        return Result.ok(dictList);
    }

}
